package com.jhx.advertisingscreen;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.callback.AbsCallback;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.Response;

public abstract class JsonCallback<T> extends AbsCallback<T> {
    @Override
    public T convertResponse(Response response) throws Exception {
        ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();

        Type type = genericSuperclass.getActualTypeArguments()[0];
        String string = response.body().string();
        T result = (T) JSON.parseObject(string, type);
        return result;
    }
}